<template>
    <div class="index">
        <div class="top">
            <div class="span">网易严选</div>
            <div class="input" @click="toSearch">
                <uni-icons class="icon" type="search" size="20"></uni-icons>
                <div class="text">点击搜索更多</div>
            </div>
            <div class="btn">登录</div>
        </div>

        <div class="scroll">
            <scroll-view class="box" scroll-x enable-flex>
                <div
                    :class="{ active: num == item.id }"
                    class="span"
                    @click="handler(item.id)"
                    v-for="(item, index) in scrollArr"
                    :key="index">
                    {{ item.name }}
                </div>
            </scroll-view>
            <div class="showdiv" v-show="show">
                <div class="max">
                    <div class="title">热门推荐</div>
                    <div class="typebox">
                        <div
                            @click="handler(item.id)"
                            :class="{ active: num == index }"
                            v-for="(item, index) in scrollArr"
                            :key="index"
                            class="type">
                            {{ item.name }}
                        </div>
                    </div>
                </div>
            </div>
            <uni-icons @click="show = !show" class="topicon" :type="show ? 'top' : 'bottom'" size="20"></uni-icons>
        </div>

        <scroll-view scroll-y class="scroll-view">
            <!-- 轮播图 -->
            <div class="swiper">
                <swiper indicator-dots autoplay circular>
                    <swiper-item v-for="(item, index) in imgArr" :key="index">
                        <image class="img" :src="item.picUrl" mode="widthFix" />
                    </swiper-item>
                </swiper>
            </div>
            <div class="text">
                <a class="wang" v-for="(item, index) in pinpaiArr" :key="index">
                    <img class="img" :src="item.icon" alt="" />
                    {{ item.desc }}
                </a>
            </div>
            <!-- 新品首发 -->
            <div class="category">
                <div class="box" v-for="(item, index) in typeArr" :key="index">
                    <img class="img" :src="item.picUrl" alt="" />
                    <text class="title">{{ item.text }}</text>
                </div>
            </div>
            <!-- 七夕 -->
            <img class="seven" src="https://yanxuan.nosdn.127.net/static-union/1691817905f740cf.gif" alt="widthMax" />
            <div class="new">--新人专享--</div>
            <div class="first">
                <div class="one">
                    <span class="text">新人专享礼包</span>
                    <img class="img" src="https://yanxuan.nosdn.127.net/static-union/1648017994dd2933.png" alt="" />
                </div>
                <div class="two">
                    <div class="top">
                        <div class="left">
                            <span class="span">福利社</span>
                            <text>今日特价</text>
                        </div>
                        <img
                            class="right"
                            src="https://yanxuan-item.nosdn.127.net/3579f9c18c174ba49bf6ac5933a22249.png?quality=75&type=webp&imageView&thumbnail=200x200"
                            alt="" />
                    </div>
                    <div class="bottom">
                        <div class="left">
                            <span class="span">新人拼团</span>
                            <text>一元包邮</text>
                        </div>
                        <img
                            class="right"
                            src="https://yanxuan-item.nosdn.127.net/bb768262fcc82c1f15e2973e42c83142.png?quality=75&type=webp&imageView&thumbnail=200x200"
                            alt="" />
                    </div>
                    <div class="money">
                        <span class="span">￥ 17.9</span>
                        <span class="span">￥ 18.9</span>
                    </div>
                </div>
            </div>
            <type :list="hotArr" />
            <!-- 商品 -->
            <goods />
            <!--  -->

            <!--  -->
        </scroll-view>
    </div>
</template>

<script lang="ts" setup>
import { ref, onMounted } from 'vue';
import Ajax from '@/api/index';
import TypeAjax from '@/api/type';
const imgArr = ref<any>([]);
const pinpaiArr = ref<any>([]);
const typeArr = ref<any>([]);
const hotArr = ref<any>([]);
const num = ref<any>(11);
const show = ref<boolean>(false);
const scrollArr = ref<any>([]);
onMounted(() => {
    getList();
    getType();
});
const getList = async () => {
    let result: any = await Ajax.reqLunbotu();
    // console.log(result);
    if (result.code == 200) {
        imgArr.value = result.data.data.focusList;
        pinpaiArr.value = result.data.data.policyDescList;
        typeArr.value = result.data.data.kingKongModule.kingKongList;
        hotArr.value = result.data.data.categoryHotSellModule.categoryList;
        // king
    }
};
const handler = (id: any) => {
    num.value = id;
    uni.navigateTo({
        url: `/pages/goodlist/index?goodId=${id}`,
    });
    // console.log(id);
};
const getType = async () => {
    let result: any = await TypeAjax.reqList();
    console.log(result);

    scrollArr.value = result.data.categoryL1List;
};
const toSearch = () => {
    uni.navigateTo({
        url: '/pages/search/index',
    });
};
</script>

<style lang="less" scoped>
.index {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    .scroll-view {
        flex: 1;
        overflow: hidden;
    }
    .top {
        display: flex;
        justify-content: space-between;
        height: 100rpx;
        margin: 10rpx 0;
        .span {
            font-weight: 900;
            margin: 0 auto;
        }
        .input {
            width: 450rpx;
            height: 60rpx;
            border-radius: 10rpx;
            line-height: 60rpx;
            background-color: lightgray;
            display: flex;
            align-items: center;

            .text {
                height: 30rpx;
                line-height: 30rpx;
                margin-left: 20rpx;
            }
            .icon {
                margin-left: 20rpx;
            }
        }
        .btn {
            width: 76rpx;
            border: 1px solid lightcoral;
            color: red;
            height: 40rpx;
            border-radius: 10rpx;
            line-height: 40rpx;
            margin: 0 auto;
            margin-top: 10rpx;
            text-align: center;
        }
    }
    .scroll {
        position: relative;
        margin-bottom: 10rpx;
        // overflow: hidden;
        .box {
            display: flex;
            overflow: hidden;
            height: 60rpx;
            width: 85%;
            .span {
                flex-shrink: 0;
                margin: 0 15rpx;
                padding: 10rpx;
                // width: 100rpx;
            }
            .active {
                border-bottom: 1px solid lightcoral;
                color: red;
            }
        }
        .showdiv {
            position: absolute;
            top: 0;
            left: 0;
            z-index: 99;
            background: rgba(116, 115, 117, 0.5);
            width: 100%;
            height: 100vh;
            .max {
                background: snow;
                .title {
                    color: #333;
                    font-size: 28rpx;
                    padding: 20rpx;
                }
                .typebox {
                    display: flex;
                    flex-wrap: wrap;
                    .type {
                        width: 100rpx;
                        color: #333;
                        font-size: 24rpx;
                        margin: 20rpx 10rpx;
                        padding: 15rpx;
                    }
                    .active {
                        border: 1px solid red;
                    }
                }
            }
        }
        .topicon {
            z-index: 100;
            position: absolute;
            right: 50rpx;
            top: 10rpx;
        }
    }

    .swiper {
        .img {
            width: 100%;
            height: 400rpx;
        }
    }
    .text {
        margin: 20rpx;
        display: flex;
        justify-content: space-around;
        .wang {
            display: flex;
            align-items: center;
            font-size: 24rpx;
            .img {
                width: 40rpx;
                height: 40rpx;
            }
        }
    }
    .category {
        display: flex;
        flex-wrap: wrap;
        padding: 10rpx;
        justify-content: space-between;
        .box {
            width: 20%;
            display: flex;
            flex-direction: column;
            align-items: center;
            .img {
                width: 120rpx;
                height: 120rpx;
            }
            .title {
                font-size: 24rpx;
                text-align: center;
            }
        }
    }
    .seven {
        width: 100%;
        height: 140rpx;
        margin: 20rpx 0;
    }
    .new {
        width: 100%;
        text-align: center;
        color: lightgray;
    }
    .first {
        // padding: 0 20rpx;
        display: flex;
        width: 100%;
        justify-content: space-around;
        padding: 10rpx;
        .one {
            display: flex;
            width: 48%;
            height: 100%;
            margin-right: 10rpx;
            flex-direction: column;
            align-items: center;
            background: lightsalmon;
            .text {
                color: #f8f8f8;
            }
            .img {
                margin: 50rpx 0;
                width: 268rpx;
                height: 268rpx;
            }
        }
        .two {
            display: flex;
            flex-direction: column;
            justify-content: space-between;
            padding-right: 20rpx;
            width: 50%;
            .top {
                background-color: aquamarine;
                width: 100%;
                display: flex;
                margin: 0;
                height: 49%;

                .left {
                    display: flex;
                    margin-left: 10rpx;
                    flex-direction: column;
                    .span {
                        margin: 20rpx 0;
                        color: antiquewhite;
                    }
                    text {
                        color: #f8f8f8;
                    }
                }
                .right {
                    width: 208rpx;
                    height: 208rpx;
                }
            }
            .bottom {
                background-color: aquamarine;
                width: 100%;
                display: flex;
                height: 49%;
                position: relative;

                .left {
                    display: flex;
                    flex-direction: column;
                    margin-left: 10rpx;
                    .span {
                        margin: 20rpx 0;
                        color: antiquewhite;
                    }
                    text {
                        background: lightsalmon;
                        text-align: center;
                        border-radius: 10rpx;
                        padding: 0 10rpx;
                        color: #f8f8f8;
                    }
                }
                .right {
                    width: 208rpx;
                    height: 208rpx;
                }
            }
            .money {
                position: absolute;
                right: 60rpx;
                bottom: -350rpx;
                width: 100rpx;
                height: 100rpx;
                border-radius: 50%;
                background: orange;
                display: flex;
                flex-direction: column;
                justify-content: center;
                align-items: center;
                opacity: 0.7;

                .span {
                    font-size: 20rpx;
                    color: #f8f8f8;
                }
            }
        }
    }
}
</style>
